<?php
/*
* @Name:    express.php
* @Version: 1.0
* @Update:  2013.2.6
* @Use:     Make the item page from express website at xx.com/express/xxx.html
* @Author:  CoderChao
*/
?>
<?php 
    header("Content-Type: text/html; charset=utf-8");
    $ChineseKeyword = rawurlencode($_GET['s']);
    $ChineseUrl = "http://www.amazon.cn/s/field-keywords=".$ChineseKeyword."?tag=nginx-23";
    if (strrpos($ChineseKeyword,'%')){
        header('HTTP/1.1 301 Moved Permanently'); 
        header("Location: $ChineseUrl");
    return;
    }else{
?>
<?php

    $PageStartTime = microtime();
    include 'config.php';
    include 'function.php';
?>
<?php

    $SearchString   = str_replace('-', ' ', clean_keyword($_GET['s']));

    $UCKeyWord      = ucwords($SearchString); // Upper case keywords,use for title or others
    
    $DomainName     = 'http://'.$_SERVER['SERVER_NAME'];    //http://www.xxx.com

    /*  Check if static file exists */
    $FileName = './express/'.md5(strtolower($SearchString)).'.txt';    //Static File Name

    if (!is_dir('./express')) { mkdir('./express',0777,TURE); }   //make directory /express/

    if( file_exists($FileName) && ( time() - filectime($FileName) < 3600*24*30 ) ) {   //abadon file if time lasts more than 30 days
        $content = file_get_contents($FileName);
        echo $content;
        return;
    }else{

    //$body = get_a9_content($SearchString,$TagID);   //got 10 items
    $body = get_express_content($SearchString);

    ob_start();
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Best Sellers of <?php echo $UCKeyWord; ?> Reviews <?php echo date("Y"); ?> ! </title>
    <meta name="robots" content="index,follow">
    <link rel="shortcut icon" type="image/x-icon" href="<?php echo $DomainName; ?>/favicon.ico">
    <link rel="canonical" href="<?php echo $DomainName; ?>/express/<?php echo strtolower(clean_keyword($_GET['s'])); ?>.html"/>
    <link rel="stylesheet" type="text/css" href="<?php echo $DomainName; ?>/style/component.css">
    <link rel="stylesheet" type="text/css" href="<?php echo $DomainName; ?>/style/searchlist.css">                    
</head>
<body class="hd" >
<div id="tbh5v0" class="mytaobao">
<div id="bodyCont" class="screen-wrap fullscreen searchlist">
        <header id="header">
            <div class="c-inav">
                <section></section>
                <section id="J_topnav">
                    <h1><span><a href="http://www.amazon.com/s/field-keywords=<?php echo rawurlencode(ucwords($SearchString)); ?>?tag=<?php echo $SearchID; ?>"><?php echo $UCKeyWord; ?></a></span></h1>
                </section>
                <section>
                    <a id="J_category" class="other red" href="http://www.amazon.com/?tag=homepage20-20" rel="nofollow">
                        <nav>Amazon</nav>
                    </a>
                </section>
            </div>
        </header>
        <section class="searchcontent">
             <section class="search-content">
                                <div class="search-list" id="J_SearchList">
                                    <hr color="#cccccc" width="100%" size="1" noshade="noshade" />
                    <?php echo $body; ?>
                </div>
            </section> 
                        <section class="guide-keyword">
  <div class="guide-keyword">
                <p><br />Bestselling At Amazon Online Store :</p>
                <h3><a href="http://www.amazon.com/s/field-keywords=<?php echo rawurlencode(ucwords($SearchString)); ?>?tag=<?php echo $SearchID; ?>"><img src="/style/amazon.png" alt="<?php echo $UCKeyWord; ?>"><br /><?php echo $UCKeyWord; ?></a></h3>

<?php
    /*  Get lat 5 Google Suggest Keywords */
    $SuggestKeywords = get_last_suggest_keywords ($SearchString);
?>
                <p><?php echo $SuggestKeywords; ?></p>
            </div>
            </section>              
            <section>
                <form action="/search.php" method="get" class="searchtxt c-form-suggest" id="J_Search2">
                    <div class="c-form-search">
                        <input type="text" class="J_autocomplete" autocomplete="off" name="s" placeholder="<?php echo $UCKeyWord; ?>" />    
                    </div>
                    <button class="searchbtn"></button>
                </form>
            </section>
        </section>
                       <footer  class="footer">
            <section class="footer-t">
                <p class="user-info">
                    <span><a href="<?php echo $DomainName; ?>/" rel="home">Home</a></span>
                    <span></span>
                </p>
                  <p class="gotop"><a id="J_GoTop" href="javascript:scroll(0,0)">top<b> </b></a></p>
               </section>
               <nav class="footer-l">
                  <a href="<?php echo $DomainName; ?>/<?php echo strtolower(clean_keyword($_GET['s'])); ?>.html" title="<?php echo $UCKeyWord; ?>"><?php echo $UCKeyWord; ?></a>
               </nav>
               <p class="copyright">&copy; 1999 - <?php echo date("Y"); ?>  <?php echo $_SERVER['HTTP_HOST']; ?>  <time itemprop="startDate" datetime="<?php date("c"); ?>"><?php echo date("Y.m.d H:i:s",time()); ?></time> <?php $PageEndTime = microtime(); echo ($PageEndTime - $PageStartTime).' s'; ?></p>
</footer>
</div>
</div>   
</body>
</html>
<?php
}   //end of get content

    /*  Compress the Html Source Code   */
    $html = compress_html(ob_get_contents());

    /*  Put HTML Code into txt files.   */
    file_put_contents($FileName, $html);
}
?>